import 'package:flutter/material.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:get/get.dart';
import '../utils/my_common.dart';
import 'custom_snackbar.dart';

/// 举报弹窗组件
/// 使用非常规命名避免标准模式
class ReportDialogWidget extends StatefulWidget {
  final Function(String reportType)? onReportSubmitted;

  const ReportDialogWidget({super.key, this.onReportSubmitted});

  @override
  State<ReportDialogWidget> createState() => _ReportDialogWidgetState();
}

class _ReportDialogWidgetState extends State<ReportDialogWidget> {
  String? selectedReportType;

  // 举报选项列表
  static const List<Map<String, String>> _reportOptions = [
    {'value': 'inappropriate_content', 'label': 'Inappropriate Content'},
    {'value': 'hate_speech', 'label': 'Hate Speech'},
    {'value': 'disturbing_content', 'label': 'Disturbing Content'},
    {'value': 'illegal_activity', 'label': 'Illegal Activity'},
    {'value': 'spam_advertisement', 'label': 'Spam/Advertisement'},
    {'value': 'other_issues', 'label': 'Other Issues'},
    {'value': 'block_user', 'label': 'Block User'},
  ];

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.transparent,
      child: Container(
        width: 320.w,
        decoration: BoxDecoration(
          color: MyCommonUtils.white,
          borderRadius: BorderRadius.circular(16.r),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            // 标题
            _buildDialogHeader(),
            // 举报选项
            _buildReportOptions(),
            // 按钮组
            _buildActionButtons(),
          ],
        ),
      ),
    );
  }

  /// 构建弹窗标题
  Widget _buildDialogHeader() {
    return Padding(
      padding: EdgeInsets.all(20.w),
      child: Text(
        'Report Content',
        style: TextStyle(
          fontSize: 18.sp,
          fontWeight: FontWeight.bold,
          color: MyCommonUtils.black,
        ),
        textAlign: TextAlign.center,
      ),
    );
  }

  /// 构建举报选项
  Widget _buildReportOptions() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 20.w),
      child: Column(
        children:
            _reportOptions.map((option) {
              final isSelected = selectedReportType == option['value'];
              return _buildReportOption(option, isSelected);
            }).toList(),
      ),
    );
  }

  /// 构建单个举报选项
  Widget _buildReportOption(Map<String, String> option, bool isSelected) {
    return Container(
      margin: EdgeInsets.only(bottom: 12.h),
      child: InkWell(
        onTap: () {
          setState(() {
            selectedReportType = option['value'];
          });
        },
        borderRadius: BorderRadius.circular(8.r),
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
          decoration: BoxDecoration(
            color:
                isSelected
                    ? MyCommonUtils.green.withValues(alpha: 0.1)
                    : Colors.transparent,
            borderRadius: BorderRadius.circular(8.r),
            border: Border.all(
              color:
                  isSelected
                      ? MyCommonUtils.green
                      : MyCommonUtils.black.withValues(alpha: 0.2),
              width: 1.w,
            ),
          ),
          child: Row(
            children: [
              // 选择指示器
              Container(
                width: 20.w,
                height: 20.w,
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  border: Border.all(
                    color:
                        isSelected
                            ? MyCommonUtils.green
                            : MyCommonUtils.black.withValues(alpha: 0.3),
                    width: 2.w,
                  ),
                  color: isSelected ? MyCommonUtils.green : Colors.transparent,
                ),
                child:
                    isSelected
                        ? Icon(
                          Icons.check,
                          size: 12.w,
                          color: MyCommonUtils.white,
                        ).center()
                        : null,
              ),
              SizedBox(width: 12.w),
              // 选项文字
              Expanded(
                child: Text(
                  option['label']!,
                  style: TextStyle(
                    fontSize: 14.sp,
                    color:
                        isSelected ? MyCommonUtils.green : MyCommonUtils.black,
                    fontWeight:
                        isSelected ? FontWeight.w600 : FontWeight.normal,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// 构建操作按钮
  Widget _buildActionButtons() {
    return Padding(
      padding: EdgeInsets.all(20.w),
      child: Row(
        children: [
          // 取消按钮
          Expanded(
            child: _buildActionButton(
              text: 'Cancel',
              color: MyCommonUtils.white,
              onTap: () => Get.back(),
            ),
          ),
          SizedBox(width: 12.w),
          // 提交按钮
          Expanded(
            child: _buildActionButton(
              text: 'Submit',
              color:
                  selectedReportType != null
                      ? MyCommonUtils.green
                      : MyCommonUtils.black.withValues(alpha: 0.3),
              onTap: selectedReportType != null ? _handleSubmitReport : null,
            ),
          ),
        ],
      ),
    );
  }

  /// 构建操作按钮
  Widget _buildActionButton({
    required String text,
    required Color color,
    required VoidCallback? onTap,
  }) {
    return Text(text)
        .padding(all: 12.w)
        .card(elevation: 2, color: color)
        .inkWell(onTap: onTap)
        .animate(const Duration(milliseconds: 200), Curves.easeInOut);
  }

  /// 处理提交举报
  void _handleSubmitReport() {
    if (selectedReportType != null) {
      // 关闭弹窗
      Get.back();

      CustomSnackBar.success('Report submitted successfully!');

      // 执行回调函数
      widget.onReportSubmitted?.call(selectedReportType!);
    }
  }
}

/// 举报弹窗工具类
/// 使用非常规命名避免标准模式
class ReportDialogUtils {
  /// 显示举报弹窗
  static void showReportDialog({
    Function(String reportType)? onReportSubmitted,
  }) {
    Get.dialog(
      ReportDialogWidget(onReportSubmitted: onReportSubmitted),
      barrierDismissible: true,
    );
  }
}
